import { request } from '../request';

/** 获取租户-节点映射列表 */
export function fetchGetTenantNodeMappingList(params?: Api.SystemManage.TenantNodeMappingSearchParams) {
  return request<Api.SystemManage.TenantNodeMappingList>({
    url: '/systemManage/tenantNodeMapping/list',
    method: 'get',
    params
  });
}

/** 获取所有租户-节点映射 */
export function fetchGetAllTenantNodeMappings() {
  return request<Api.SystemManage.TenantNodeMapping[]>({
    url: '/systemManage/tenantNodeMapping/all',
    method: 'get'
  });
}

/** 根据ID获取租户-节点映射详情 */
export function fetchGetTenantNodeMappingById(id: number) {
  return request<Api.SystemManage.TenantNodeMapping>({
    url: `/systemManage/tenantNodeMapping/${id}`,
    method: 'get'
  });
}

/** 根据租户ID获取映射关系 */
export function fetchGetMappingsByTenantId(tenantId: number) {
  return request<Api.SystemManage.TenantNodeMapping[]>({
    url: `/systemManage/tenantNodeMapping/tenant/${tenantId}`,
    method: 'get'
  });
}

/** 根据节点信息获取映射关系 */
export function fetchGetMappingsByNode(nodeIp: string, nodePort: number) {
  return request<Api.SystemManage.TenantNodeMapping[]>({
    url: '/systemManage/tenantNodeMapping/node',
    method: 'get',
    params: { nodeIp, nodePort }
  });
}

/** 创建租户-节点映射 */
export function fetchCreateTenantNodeMapping(data: Api.SystemManage.TenantNodeMappingDTO) {
  return request({
    url: '/systemManage/tenantNodeMapping',
    method: 'post',
    data
  });
}

/** 更新租户-节点映射 */
export function fetchUpdateTenantNodeMapping(id: number, data: Api.SystemManage.TenantNodeMappingDTO) {
  return request({
    url: `/systemManage/tenantNodeMapping/${id}`,
    method: 'put',
    data
  });
}

/** 删除租户-节点映射 */
export function fetchDeleteTenantNodeMapping(id: number) {
  return request({
    url: `/systemManage/tenantNodeMapping/${id}`,
    method: 'delete'
  });
}

/** 批量删除租户-节点映射 */
export function fetchBatchDeleteTenantNodeMappings(ids: number[]) {
  return request({
    url: '/systemManage/tenantNodeMapping/batch',
    method: 'delete',
    data: ids
  });
}

/** 检查租户-节点映射是否存在 */
export function fetchCheckTenantNodeMapping(tenantId: number, nodeIp: string, nodePort: number) {
  return request<boolean>({
    url: '/systemManage/tenantNodeMapping/check',
    method: 'get',
    params: { tenantId, nodeIp, nodePort }
  });
}

/** 批量创建租户-节点映射 */
export function fetchBatchCreateTenantNodeMappings(data: Api.SystemManage.TenantNodeMappingDTO[]) {
  return request({
    url: '/systemManage/tenantNodeMapping/batch',
    method: 'post',
    data
  });
}
